package util;

import java.net.URI;
import java.net.URL;
import java.util.Date;
import java.util.Locale;

import org.springframework.util.Assert;

/**
 * @author 1203056
 * @version Id: ClassUtils.java, v 0.1 2021-09-07 16:59 1203056 Exp $
 */
public class ClassUtils {

    /**
     * Check if the given type represents a "simple" value type:
     * a primitive, a String or other CharSequence, a Number, a Date,
     * a URI, a URL, a Locale or a Class.
     * @param clazz the type to check
     * @return whether the given type represents a "simple" value type
     */
    public static boolean isSimpleType(Class<?> clazz) {
        return org.springframework.util.ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.isEnum() || CharSequence.class.isAssignableFrom(clazz)
               || Number.class.isAssignableFrom(clazz) || Date.class.isAssignableFrom(clazz) || clazz.equals(URI.class) || clazz.equals(URL.class) || clazz.equals(Locale.class)
               || clazz.equals(Class.class);
    }

    public static boolean isSimpleProperty(Class<?> clazz) {
        Assert.notNull(clazz, "Class must not be null");
        return isSimpleType(clazz) || (clazz.isArray() && isSimpleType(clazz.getComponentType()));
    }

}
